<?php
namespace app\user\controller;
use think\Db;

class Common{
    public function __construct()
    {
        //统一
        $this->m = request()->request('action');
        $this->cid = request()->request('cid');

        $debug = true;
        if($debug){

            if(!is_dir(APP_PATH."/Debug")){
                mkdir(APP_PATH."/Debug");
            }
            if(!is_file(APP_PATH."/Debug/record")){
                file_put_contents(APP_PATH."/Debug/record",'');
            }
            $url_str = explode("?",$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
            $url = $url_str[0];
            $request = '';
            foreach ($_REQUEST as $k => $v){
                $request .= $k."=".$v."&";
            }
            $request = substr($request,0,strlen($request)-1);
            if($request !='')
                $url .= "?".$request;
            $content = "<hr>\r\n<div style='padding: 10px;'>\r\n<a target='_blank' href='http://".$url."'>http://".$url."</a></div>\r\n<pre style='font-size: 14px; margin-left: 10px;'>\r\n数据参数：\r\n".print_r($_REQUEST,true)."\r\n文件参数：\r\n".print_r($_FILES,true)."</pre>\r\n</div>\r\n<div style='margin-left: 10px; font-size: 13px'><span>".$_SERVER['HTTP_USER_AGENT']." ".$_SERVER['REMOTE_ADDR']."</span><span style='float: right; margin-right: 10px;'>".date("Y-m-d H:i:s") ."</span></div></div>\r\n<hr>\r\n";
            if(filesize(APP_PATH."/Debug/record") > 1048576){
                file_put_contents(APP_PATH."/Debug/record","");
            }
            file_put_contents(APP_PATH."/Debug/record",$content.file_get_contents(APP_PATH."/Debug/record"));
        }

        function upload()
        {
            $config = Db::table('material_config')->where('id',1)->find();
            config([
                'UPLOAD_SITEIMG_QINIU'=>[
                    'maxSize'          => 5 * 1024 * 1024,//文件大小
                    'rootPath'         => './',
                    'saveName'         => ['uniqid', ''],
                    'driver'           => 'Qiniu',
                    'driverConfig' => [
                        'secretKey' => $config['secretKey'],
                        'accessKey' => $config['accessKey'],
                        'domain'    => $config['domain'],
                        'bucket'    => $config['bucket'],
                    ],
                ],
                'file_size'=>$config['file_size']
            ]);
            $setting = config('UPLOAD_SITEIMG_QINIU');
            $Upload = new \think\Upload($setting);
            $info = $Upload->upload($_FILES);
            return $info;
        }

    }

}